home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7307 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  48 lines

  1. Path: news.voicenet.com!news
  2. From: kobak@voicenet.com (Peter Kobak)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: meaning of int a::*b
  5. Date: 22 Feb 1996 16:01:23 GMT
  6. Organization: Voicenet - Internet Access - (215)674-9290
  7. Message-ID: <4gi40j$kou@news.voicenet.com>
  8. NNTP-Posting-Host: ivyland243.voicenet.com
  9. X-Newsreader: NeoLogic News for OS/2 [version: 4.2]
  10.  
  11. In message <31284007.7977@mercury.co.il> - Shlomo Wygodny 
  12. <wygodny@mercury.co.il> writes:
  13. :>
  14. :>In the following (compilable) program:
  15. :>
  16. :>class a{};
  17. :>int a::*b;
  18. :>void main(){}
  19. :>
  20. :>Does someone know what is the meaning of int a::*b; ?
  21. :>It's probably a declaration of a variable b of type int a::* . 
  22. :>But what
  23. :>does it mean? What can be assigned to it?
  24. :>
  25. :>- Shlomo.
  26.  
  27. I tried to post your question in .moderated, but it got rejected for being 
  28. trivial. Well, it was new to me; I've seen pointers to member functions, but 
  29. not member data. The .moderated moderator was kind enough to provide an 
  30. explanation which follows:
  31.  
  32. {This declares 'b' to be a "pointer to an 'int' member of 'a'". A
  33. suitable assignment would be something like:
  34.   class a { public: int bar; };
  35.   int a::*b = &a::bar;
  36. and a corresponding use would be
  37.   a aobj;
  38.   aobj.*b = 17;        // assignment
  39.   int dummy = aobj.*b; // access
  40. Using pointer-to-member you can make the member which is to be accessed
  41. modifyable. -mod}
  42.  
  43. ================
  44. Peter Kobak
  45. kobak@voicenet.com
  46.  
  47.  
  48.